package com.woniu.controller;/*
 *
 * @author   米雷
 * @Description 消息中心
 * @Date:create in 21:14 2020-03-27
 *
 * */

import com.woniu.pojo.Mess;
import com.woniu.service.MessService;
import com.woniu.userLog.LogPoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "消息中心")
@CrossOrigin(allowCredentials = "true",maxAge = 3600)
@Controller
@RequestMapping("/mess")
public class MessController {
    @Autowired
    MessService messService;

    /*
    *
    * 查看自己受到的信息
    * */
    @GetMapping("/getRec")
    @ResponseBody
    @ApiOperation(value = "收到的消息")
    @LogPoint("用户查看收到的消息")
    public List<Mess> getRecMess(Long id){
            List<Mess> list= messService.getRecMess(id);
            return list;
    }

    /*
     *
     * 查看自己发送的信息
     * */
    @GetMapping("/getSend")
    @ResponseBody
    @ApiOperation(value = "发出的消息")
    @LogPoint("用户查看发出的消息")
    public List<Mess> getSedndMess(Long id){
        List<Mess> list= messService.getSendMess(id);
        return list;
    }
    /*
     *
     * 发送信息
     *
     * */
    @PutMapping("/add")
    @ResponseBody
    @ApiOperation(value = "发送消息")
    @LogPoint("用户发出消息")
    public String addMess(Mess mess){
        String res=messService.addMess(mess);
        return res;
    }
    /*
     *
     * 删除受到的信息
     *
     * */
    @PutMapping("/delRec")
    @ResponseBody
    @ApiOperation(value = "删除收到的消息")
    @LogPoint("用户删除收到的消息")
    public String delRecMess(Long id){
        String res=messService.delRecMess(id);
        return res;
    }

    /*
     *
     * 删除发出的信息
     *
     * */
    @PutMapping("/delSend")
    @ResponseBody
    @ApiOperation(value = "删除发出的消息")
    @LogPoint("用户删除发出的消息")
    public String delSendMess(Long id){
        String res=messService.delSendMess(id);
        return res;
    }

    @GetMapping("/getSearch")
    @ResponseBody
    @ApiOperation(value = "根据搜索查询")
    @LogPoint("用户搜索消息")
    public List<Mess> getBySearch(Long id,String mes){
        List<Mess> list =messService.getBySearch(id,mes);
        return list;
    }
}
